﻿using SdmxMl.Structure;

namespace SasPlugIn.DB
{
    /// <summary>
    /// Represents a column of a Db table
    /// </summary>
    public class DbColumn
    {
        #region Internal Members

        public const int DEFAULT_STRING_LEN = 30;

        #endregion

        #region Properties

        /// <summary> Column name in DB Table</summary>
        public string Name { get; private set; }

        /// <summary> Column meta information </summary>
        public string MetaName { get; set; }



        /// <summary> SDMX Format associated to column</summary>
        public TextFormatType TFormat { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Simple C'tor with column name, assumes text format and default length
        /// </summary>
        /// <param name="colName"> Column name</param>
         public DbColumn(string colName) : this(colName, DEFAULT_STRING_LEN) { }


        /// <summary>C'tor</summary>
        /// <param name="colName">column name</param>
        /// <param name="maxLen">column text max length</param>
        public DbColumn(string colName, int maxLen)
        {
            if (maxLen <= 0)
            {
                maxLen = DEFAULT_STRING_LEN;
            }

            // Compose a default string format if none specified
            TextFormatType tft = new TextFormatType();
            tft.maxLength = maxLen.ToString();
            tft.TextType = TextTypeType.String;

            Name = colName;
            TFormat = tft;
        }

        /// <summary>C'tor with specified format</summary>
        /// <param name="colName"> Column name</param>
        /// <param name="tft">SDMX format to associate to column</param>
        public DbColumn(string colName, TextFormatType tft)
        {
            Name = colName;
            TFormat = tft;

        }

        #endregion
    }
}
